using System;
using System.Linq;
using System.Text;
using System.Web;
using MarsExplorerWebSite.Model;

namespace MarsExplorerWebSite.Functions
{
    public class getTeamTurn : FunctionBase
    {
        private MarsExplorerEntities dbContext;
        public int TeamID { get; set; }
        public getTeamTurn(HttpContext context)
            : base(context)
        {
            InitializeProperties();
        }

        public override string Execute()
        {
            StringBuilder sb = new StringBuilder();
            try
            {
                var tr = from x in dbContext.TeamsTurns where x.TeamID == TeamID select x;

                int i = 0;
                foreach (TeamsTurn t in tr)
                {
                    i += 1;
                    sb.Append( t.Value);
                    if (i != tr.Count())
                    {
                        sb.Append(";");
                    }
                }
                return sb.ToString();
            }
            catch (Exception)
            {

                return "ERROR";
            }
        }

        public override void InitializeProperties()
        {
            try
            {
                TeamID = Convert.ToInt32(Parameters["teamid"]);
                dbContext = new MarsExplorerEntities();
            }
            catch (Exception e)
            {
                string message = "";
                #if DEBUG
                message += " : " + e.ToString();
                #endif
            }
        }
    }
}